package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Cart;
import com.foreknow.elmboot.po.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    /**
     * 根据userId查询购物车列表
     * @param
     * @return
     */
//    @Select("select  * FROM cart where businessId=#{businessId} AND userId=#{userId}")

    List<Cart> listCart(Cart cart);

    /**
     * 添加
     *
     * @param cart
     * @return
     */
    @Insert("INSERT into cart(cartId,foodId,businessId,userId,quantity) VALUES(#{cartId},#{foodId},#{businessId},#{userId},1)")
    int addCart(Cart cart);

    /**
     * 更新数量
     * @param cart
     * @return
     */

    @Update("UPDATE cart set quantity=#{quantity} where foodId=#{foodId} and businessId =#{businessId}")
    int upDate(Cart cart);

    /**
     *
     * @param cart
     * @return
     */
    @Delete("delete  from cart where foodId =#{foodId} and userId=#{userId} and businessId=#{businessId}")
    int deleteCart(Cart cart);
}
